<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>待处理的</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/static/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/css/sm.min.css">
    <link rel="stylesheet" href="/static/css/sm-extend.min.css">

    <!--icon css-->
    <!--<link rel="stylesheet" href="css/icon-style.css">-->


    <!--重写css-->
    <style>
        .tc{
            width: 100%;
            height: 2rem;
        }
        .commodityStatus{
            border: solid .2rem red;color: red;font-weight: 800;
            transform:rotate(-8deg);
            -ms-transform:rotate(-8deg); 	/* IE 9 */
            -moz-transform:rotate(-8deg); 	/* Firefox */
            -webkit-transform:rotate(-8deg); /* Safari 和 Chrome */
            -o-transform:rotate(-8deg); 	/* Opera */

        }

    </style>
</head>

<body>
<!--头部-->
<header class="bar bar-nav">
    <a class="icon icon-left pull-left" href="JavaScript:history.back(-1)"></a>
    <h1 class="title">待处理的</h1>
</header>

<!-- 内容区-->
<div class="content">

</div>

<script type='text/javascript' src='/static/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/js/sm-extend.min.js' charset='utf-8'></script>
<script type="text/javascript" src="/static/js/deatilPage.js" charset="utf-8"></script>
<script>

    $(document).ready(function () {
        $.ajax({
            type: "post",
            url: "/front/order/readUndoOrderList",
            dataType: "json",
            success: function (re) {
                if (!re.status) {
                    var data = re.data;
                    if (!data.length){
                        $.toast("没有待处理的订单！");
                        $('.content').append("<p class=\"text-center\">没有待处理的订单</p>");
                    }else {
                        var result = '';
                        for (var i = 0;i<data.length;i++){
                            var star = new Array();//新建一个数组，
                            star = data[i].good_img.split(',');//分割图片
                            switch (data[i].status) {
                                case -1:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"text-center\"><b>交易已被取消</b>" ;
                                            if(data[i].note != ''){
                                                result+= "<br />取消原因:"+data[i].note;
                                            }
                                    result+=
                                        "</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                                    break;
                                case 0:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "            <div class=\"item-inner\">\n" +
                                        "                <div class=\"commodityStatus\">\n" +
                                        "                    已被拍下\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"button button-light pull-right cancel\" data-id='"+data[i].good_id+"'data-no='"+data[i].order_no+"'>取消交易</div>\n"+
                                        "<div class=\"button button-light pull-right\" data-no='"+data[i].order_no+"' onclick='sure(this)' style=\"margin-right:.5rem \">确认</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                                    break;
                                case 1:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"button button-light pull-right cancel\" data-id='"+data[i].good_id+"'data-no='"+data[i].order_no+"'>取消交易</div>\n"+
                                        "                    <div class=\"text-center\">已确认，等待线下交易中</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                                    break;
                                case 4:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "            <div class=\"item-inner\">\n" +
                                        "                <div class=\"commodityStatus \" style='border: solid .2rem #0894ec;color: #0894ec;'>\n" +
                                        "                    已完成\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"text-center\" >交易已完成等待买家对您做出评价</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                                    break;
                                case 5:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "            <div class=\"item-inner\">\n" +
                                        "                <div class=\"commodityStatus color-primary\">\n" +
                                        "                    已完成\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"text-center\" >交易已完成等待买家对您做出评价</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                                    break
                                default:
                                    result+=
                                        "<div class=\"card\">\n" +
                                        "        <div class=\"card-header\">\n" +
                                        "            <div class=\"item-media\" style=\"width: 70%\">\n" +
                                        "                <img src=\""+star[0]+"\" width=\"44\" style=\"border-radius: 5px;margin-right:0.5rem;float: left\">\n" +
                                        "                <div class=\"item-title\" >\n" +
                                        "                    <span>"+data[i].name+"</span><br>\n" +
                                        "                    <span style=\"font-size: 0.4rem!important; color: red\">￥"+data[i].pay+"</span>\n" +
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "        <div class=\"card-footer\">\n" +
                                        "            <div class=\"\" style=\"width: 100%\">\n" +
                                        "                <div class=\"item-inner\">\n" +
                                        "                    <div class=\"item-title\">联系人："+data[i].username+"<a href=\"tel:"+data[i].phone+"\"> <span class=\"icon icon-phone\"></span></a></div>\n" +
                                        "                    <div class=\"item-title\">预定交易地址：</div>\n" +
                                        "                    <div class=\"item-text\">"+data[i].address+"</div>\n" +
                                        "                    <div class=\"button button-light pull-right cancel\" data-id='"+data[i].good_id+"'data-no='"+data[i].order_no+"'>取消交易</div>\n"+
                                        "                    <div class=\"text-center\">已确认，等待线下交易中</div>\n"+
                                        "                </div>\n" +
                                        "            </div>\n" +
                                        "        </div>\n" +
                                        "    </div>";
                            }
                        }
                        $('.content').append(result);
                    }
                }else {
                    $.toast(re.msg);
                }
            }
        });
    });

//确认交易
    function sure(obj){
        var orderNo = $(obj).attr('data-no');
        console.log(orderNo);
        $.confirm('确认交易', function () {
                $.ajax({
                    type: "post",
                    url: "/front/order/dealOrder",
                    data: {orderNo: orderNo},
                    dataType: "json",
                    success: function (re) {
                        if (!re.status) {
                            $.toast(re.msg);
                            setTimeout(window.location.reload(),500);
                        } else {
                            $.toast(re.msg);
                        }
                    }
                });
            }
        );
    }
    //取消交易
    $(document).on('click', '.cancel',function (remove) {
        var remove = $(this);
        var goodId = remove.attr('data-id');
        var orderNo = remove.attr('data-no');
        $.prompt('取消理由：', function (value) {
            $.confirm('确定取消交易吗?',
                function () {
                    $.ajax({
                        type: "post",
                        url: "/front/order/cancelOrder",
                        data: {goodId: goodId,orderNo:orderNo,msg:value},
                        dataType: "json",
                        success: function (re) {
                            if (!re.status) {
                                $.toast(re.msg);
                                setTimeout(window.location.reload(),1000);
                            } else {
                                $.toast(re.msg);
                            }
                        }
                    });
                }
            );
        });
    });
</script>
</body>

</html>